using B.S.Data.MES.API.Applications.BaseData.Command.SupplierCommand;
using B.S.Domain.BasicData.SupplierManagement;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using System.Linq;
using System.Threading.Tasks;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.SupplierCommandHandlers
{
    public class PLDeleSupplierCommandHandlers : IRequestHandler<PLDeleSupplierCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<Supplier> supplierRepository;

        public PLDeleSupplierCommandHandlers(IBaseRepository<Supplier> supplierRepository)
        {
            this.supplierRepository = supplierRepository;
        }

        public async Task<APIRequst<int>> Handle(PLDeleSupplierCommand request, CancellationToken cancellationToken)
        {
            APIRequst<int> requst = new APIRequst<int>();
            requst.Code = RequstCode.成功;
            var path = supplierRepository.GetAll().Where(o => request.Ids.Contains(o.SupplierId)).ToList();
            foreach (var item in path)
            {
                item.isDel = true;
            }
            await supplierRepository.UpdateRange(path);
            return await Task.FromResult(requst);
        }
    }
}